#include "TcpServer.hpp"
#include "Protocol.hpp"
#include "NetCal.hpp"

using namespace SocketModule;

void Usage(std::string proc)
{
    std::cout << "Usage: " << proc << " port" << std::endl;
}

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t server_port = std::stoi(argv[1]);


    std::unique_ptr<Cal> cal = std::make_unique<Cal>();

    std::unique_ptr<Protocol> protocol = std::make_unique<Protocol>([&cal](Request &req)->Response{
        return cal->Execute(req);
    });

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(server_port, [&protocol](std::shared_ptr<Socket> &sock, InetAddr &client){
        protocol->GetRequest(sock, client);
    });
    tsvr->Start();
    return 0;
}